//
//  "$Id: AudioIn.h 91860 2012-12-08 09:18:30Z li_weijun $"
//
//  Copyright (c)1992-2008, ZheJiang Dahua Technology Stock CO.LTD.
//  All Rights Reserved.
//
//	Description:	
//	Revisions:		Year-Month-Day  SVN-Author  Modification
//

#ifndef __AUDIO_IN_API_H__
#define __AUDIO_IN_API_H__

#include "Defs.h"
#include "Types.h"

#ifdef __cplusplus
extern "C" {
#endif

/// \defgroup AudioInAPI API Audio Input 
/// 音频输入接口
/// \n 调用流程图:
/// \code
///    ================================
///               |
///      getAudioInputChannels
///               |
///        createAudioInput
///               |
///            addRef
///               |
///            release
///               |
///    ================================
/// \endcode
/// @{


///音频输入源
typedef enum AudioSource 
{
    NONE_IN_TYPE = 0,
    EXTERNAL_IN_TYPE,  //外部输入
    MIC_IN_TYPE,
    LINE_IN_TYPE,
    HDMI_IN_TYPE   
} AudioSource;

typedef enum SampleFormat 
{
    SAMPLE_FMT_NONE = -1,
    SAMPLE_FMT_U8,
    SAMPLE_FMT_S16,
    SAMPLE_FMT_S32,
    SAMPLE_FMT_FLT,
    SAMPLE_FMT_U8P,
    SAMPLE_FMT_S16P,
    SAMPLE_FMT_S32P,
    SAMPLE_FMT_FLTP,
    SAMPLE_FMT_G711A,
    SAMPLE_FMT_G711U,
    SAMPLE_FMT_NB
} SampleFormat;

typedef enum AudioInLayout 
{
    AI_NORMAL = 0, /* Normal      */
    AI_MIC_REF,    /* chanel layout: [mic:ref];*/
    AI_REF_MIC,    /* chanel layout: [ref:mic];*/
    AI_BUTT
} AudioInLayout;

typedef struct AudioInAttr 
{
  char pcAudioNode[32];
  SampleFormat enSampleFormat;
  unsigned int u32Channels;
  unsigned int u32SampleRate;
  unsigned int u32NbSamples;
  AudioInLayout enAiLayout;
  AudioSource	source;	///< 音频输入源，内部硬件产生或外部输入
  unsigned char isNeedResampler; ///< 是否需要重采样  
} AudioInAttr;

/// 音频输入数据包结构，128字节
typedef struct AudioInPacket
{
	/// 待写入的帧数据缓冲指针
	uchar *buffer;

	/// 待写入的帧数据长度。
	ulong	length;

    ///< 时间戳，毫秒为单位
	uint64	pts;		

	/// 保留
	int reserved[6];
}AudioInPacket;

/// 音频输入接口，512字节
typedef struct AudioInput
{
	/// 底层私有数据
	void *priv;

	/// 增加接口引用
	int (*addRef)(struct AudioInput *thiz);

	/// 释放接口
	int (*release)(struct AudioInput *thiz);

	/// 设置AudioIn音频属性
	int (*setChnAttr)(struct AudioInput *pThiz, AudioInAttr aiAttr);

	/// 启动AudioIn音频通道
	int (*start)(struct AudioInput *thiz);

	/// 关闭AudioIn音频通道
	int (*stop)(struct AudioInput *thiz);

	/// 从外部输入音频数据
	int (*putPacket)(struct AudioInput *pThiz, AudioInPacket *packet); 

	///< 保留字节
	int reserved[122];
} AudioInput;


/// 得到音频输入通道的个数
int PAL_API getAudioInputChannels();


/// 视频输入接口描述，128字节
typedef struct AudioInDesc
{
	int				channel;		///< 音频输入物理通道号
	int				card;			///< 子卡槽位号，0表示主板，>0表示子卡
	int				reserved[29];	///< 保留
} AudioInDesc;


/// 创建视频输入接口
///
/// \param [in] desc 视频输入接口描述结构VideoInDesc指针
/// \param [out] audioInput 视频输入接口指针的指针
/// \retval <0 创建失败
/// \retval 0 创建成功
int PAL_API createAudioInput(AudioInDesc *desc, AudioInput **audioInput);


/// @} end of group

#ifdef __cplusplus
}
#endif

#endif //__AUDIO_IN_API_H__

